package com.servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.java.Data;
import com.java.ManagerController;
import com.service.LiuYan;
import com.service.Manager;import com.sun.corba.se.spi.activation.InitialNameServicePackage.NameAlreadyBound;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("name");
		String password=request.getParameter("password");
		Data d=new Data();
		Manager m=new Manager();
		m.setName(name);
		m.setPassword(password);
		ManagerController mc=new ManagerController();
		ArrayList<LiuYan> mydata=new ArrayList<LiuYan>();
		ResultSet rs=d.getLiuyan();
		if (mc.managerlogin(m)>0) {
			try {
				
				while (rs.next()) {
					LiuYan ly=new LiuYan();
					ly.setId(rs.getString("id"));
					ly.setUserName(rs.getString("userName"));
					ly.setTel(rs.getString("tel"));
					ly.setEmail(rs.getString("email"));
					ly.setContent(rs.getString("content"));
					ly.setTime(rs.getLong("time"));
					mydata.add(ly);					
				}
			}
			catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
			if(mydata.size()>0){
				request.setAttribute("liuyan", mydata);
			}
			else{
				request.setAttribute("liuyan", null);
			}
			request.getRequestDispatcher("liuyanlist.jsp").forward(request, response);
		}
		
		


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
